package com.cungmua.app.task;

import android.content.Context;

import com.cungmua.app.handler.BaseAuthenticatedRequestHandler;
import com.cungmua.app.handler.OrderDetailsHandler;
import com.cungmua.app.model.request.OrderDetailsRequest;
import com.cungmua.app.model.response.OrderDetailsResponse;

import retrofit.RetrofitError;

/**
 * Created by kelvin.nguyen on 7/24/14.
 */
public class OrderDetailTask extends AuthenticatedTask<OrderDetailsRequest,Void,OrderDetailsResponse> {
    private Context context;
    private OrderDetailsHandler handler;

    public OrderDetailTask(Context context, OrderDetailsHandler handler) {
        this.context = context;
        this.handler = handler;
    }
    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected OrderDetailsResponse doInBackground() throws RetrofitError {
        OrderDetailsRequest request=params[0];
        return service.getOrderDetail(request.toFieldMap());
    }

    @Override
    protected BaseAuthenticatedRequestHandler getHandler() {
        return handler;
    }

    @Override
    protected void onSuccess(OrderDetailsResponse orderDetailsResponse) {
        handler.onOrderDetail(orderDetailsResponse);
    }
}
